import http from "../../../lang/http";


/**
 * 重建表格配置
 *
 * 重新抓取数据库数据，之后刷新所有配置
 *
 * @returns {Promise<{data: Object, code: Number}>}
 */
const rebuild = ()=> {
    return http.ajax({
        url: '/db/reverse/reset',
        method: 'POST',
        params: {schemaName: 'med'}
    });
}

/**
 * 重建表格配置
 *
 * 重新抓取数据库数据，之后刷新所有配置
 *
 * @param params
 * @returns {Promise<{data: Object, code: Number}>}
 */
const rebuildTable = (params) => {
    // 代码生成请求
    return http.ajax({
        url: '/db/reverse/rebuild',
        method: 'GET',
        params: params
    })
}

/**
 * 查询代码分组配置
 * @returns {Promise<{data: Object, code: Number}>}
 */
const queryCodeGroup = () => {
    return Layers.ajax({
        url: '/db/code/group/list',
        method: 'GET',
        params: {group: 'default'}
    });
}

/**
 * 生成代码
 *
 * @param params
 * @returns {Promise<{data: Object, code: Number}>}
 */
const getCode = (params) =>{
    return Layers.ajax({
        url: '/db/reverse/code',
        method: 'GET',
        params: params,
        responseType: 'text'
    })
}

/**
 * 查询数据列表
 *
 * @param request
 * @returns {Promise<{total: number, code: number, list: *[]} | *>}
 */
const list = (request) => {
    return Layers.ajax({
        url: '/db/mapping/page',
        method: 'GET',
        params: request.params
    })
}


export default {list, rebuild, queryCodeGroup, rebuildTable, getCode}